import random
from datetime import datetime

from faker import Faker


class FakerDataUtil:

    faker = Faker("zh-CN")

    @classmethod
    def faker_user_name(cls):
        """
        :return: random generate unique username
        """
        return cls.faker.unique.name()

    @classmethod
    def faker_phone_number(cls):
        """
        :return: The phone number is randomly generated
        """
        return cls.faker.phone_number()

    @classmethod
    def faker_ssn(cls):
        """
        :return: The ssn is randomly generated
        """
        return cls.faker.ssn()

    @classmethod
    def faker_random_text(cls, length=20):
        """
        :param length: The default length is 20 characters
        :return: Randomly generated text information max_nb_chars(maximum character length)
        """
        return cls.faker.text(max_nb_chars=length, ext_word_list=None)

    @classmethod
    def faker_company(cls):
        """
        :return: Randomly generate the company name
        """
        return cls.faker.company()

    @classmethod
    def faker_address(cls):
        """
        :return: Randomly generate address information
        """
        return cls.faker.address()

    @classmethod
    def random_generate_integer(cls, min_num, max_num):
        """
        :param min_num: Minimum value
        :param max_num: Maximum value
        :return: Randomly generate positive integers
        """
        random_num = random.randint(min_num, max_num)
        return random_num

    @classmethod
    def random_generate_true_or_false(cls):
        """
        :return: Randomly generate True or False
        """
        result = bool(random.getrandbits(1))
        return result

    @classmethod
    def faker_email(cls):
        """
        :return: Randomly generated mailbox
        """
        email = cls.faker.unique.email()
        return email

    @classmethod
    def faker_province(cls):
        """
        :return: Randomly generated province
        """
        province = cls.faker.province()
        return province

    @classmethod
    def faker_job(cls):
        """
        :return: Randomly generated jobs
        """
        job = cls.faker.job()
        return job

    @classmethod
    def faker_password(cls, length=8, special_chars=True, digits=True, upper_case=True, lower_case=True):
        """
        :param length: Default password length
        :param special_chars: Whether special characters are included
        :param digits: Whether special numbers are included
        :param upper_case: Whether to include uppercase letters
        :param lower_case: Whether to include lowercase letters
        :return:Randomly generated password
        """
        password = cls.faker.unique.password(length, special_chars=special_chars, digits=digits, upper_case=upper_case, lower_case=lower_case)
        return password

    @classmethod
    def faker_string(cls):
        """
        :return: Randomly generated string
        """
        pystring = cls.faker.unique.pystr()
        return pystring

    @classmethod
    def faker_number(cls):
        """
        :return: Generate int integers randomly
        """
        pyint = cls.faker.pyint()
        return pyint

    @classmethod
    def faker_ipv4(cls):
        """
        :return: Generate ipv4 randomly
        """
        ipv4 = cls.faker.ipv4()
        return ipv4

    @classmethod
    def faker_url(cls):
        """
        :return: Generate url randomly
        """
        url = cls.faker.url()
        return url

    @classmethod
    def faker_copyright(cls):
        """
        :return: Generate copyright information
        """
        # 获取当前年份
        year = datetime.now().year
        return f"© {year} 上海xxx网络科技有限公司. All rights reserved."

